package persentation.presentStudent;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import businesslogic.chooseCourseBl.ChooseCourseController;
import businesslogic.courseBl.CourseController;
import businesslogic.informBl.InformController;
import businesslogic.userBl.StudentController;

public class ButtonPanel extends JPanel {
	private static Image BOTTOM=new ImageIcon("Graphics/studentGraphics/bottom.png").getImage();
	private static ImageIcon SHOWSCORE=new ImageIcon("Graphics/studentGraphics/showScore.png");
	private static ImageIcon CHANGE_PASSWRORD=new ImageIcon("Graphics/studentGraphics/changePassword.png");
	private static ImageIcon CHOOSE_COURSE=new ImageIcon("Graphics/studentGraphics/chooseCourse.png");
	private static ImageIcon MYCOURSE=new ImageIcon("Graphics/studentGraphics/myCourse.png");
	private static ImageIcon DELETE_COURSE=new ImageIcon("Graphics/studentGraphics/deleteCourse.png");
	private MyTabbedPane tabbedPane;
	private ShowCoursePanel showCoursePanel;
	private ChooseCourseController chooseCourseController;
	private CourseController courseController;
	private StudentController studentController;
	private InformController informController;
	private ShowScorePanel showScorePanel;
	private ChangePasswordPanel changePasswordPanel;
	private ChooseCoursePanel chooseCoursePanel;
	private DeleteCoursePanel deleteCoursePanel;
	private BottomPanel bottomPanel;
	

	/**
	 * Create the panel.
	 */
	public ButtonPanel(final MyTabbedPane tabbedPane,String studentId) {
		
		chooseCourseController = new ChooseCourseController(studentId);
		studentController = new StudentController(studentId);
		courseController = new CourseController(studentId);
		informController=new InformController(studentId);
		
		showCoursePanel = new ShowCoursePanel(chooseCourseController);
		showCoursePanel.setTabbedPane(tabbedPane);
		chooseCoursePanel = new ChooseCoursePanel(chooseCourseController,
				courseController, studentController);
		chooseCoursePanel.setTabbedPane(tabbedPane);
		deleteCoursePanel = new DeleteCoursePanel(chooseCourseController);
		showScorePanel = new ShowScorePanel(chooseCourseController,studentController);
		changePasswordPanel = new ChangePasswordPanel(studentController);
		bottomPanel=new BottomPanel(studentController);
		tabbedPane.addBottom(bottomPanel);
		
		
		setSize(200,600);
		this.tabbedPane=tabbedPane;
		setLayout(null);
		tabbedPane.addOne("欢迎使用", bottomPanel);
		

		JButton button = new JButton("选择课程");
		button.setIcon(CHOOSE_COURSE);
		button.setBounds(17, 94, 167, 53);
		add(button);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.addOne("选择课程", chooseCoursePanel);
			}
		});
		button.setFont(new Font("微软雅黑", Font.BOLD, 20));

		JButton btnNewButton = new JButton("我的课程");
		btnNewButton.setIcon(MYCOURSE);
		btnNewButton.setBounds(14, 35, 170, 50);
		add(btnNewButton);
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.addOne("我的课程", showCoursePanel);
				showCoursePanel.fillTable();
			}
		});
		btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 20));

		JButton button_2 = new JButton("查看成绩");
		button_2.setIcon(SHOWSCORE);
		button_2.setBounds(14, 214, 170, 50);
		add(button_2);
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.addOne("查看成绩", showScorePanel);
				showScorePanel.refresh();
			}
		});
		button_2.setFont(new Font("微软雅黑", Font.BOLD, 20));

		JButton button_3 = new JButton("修改密码");
		button_3.setIcon(CHANGE_PASSWRORD);
		button_3.setBounds(17, 274, 170, 50);
		add(button_3);
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.addOne("修改密码", changePasswordPanel);
			}
		});
		button_3.setFont(new Font("微软雅黑", Font.BOLD, 20));

		JButton button_1 = new JButton("退选课程");
		button_1.setIcon(DELETE_COURSE);
		button_1.setBounds(17, 154, 170, 50);
		add(button_1);
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.addOne("退选课程", deleteCoursePanel);
				deleteCoursePanel.fillTable();

			}
		});
		button_1.setFont(new Font("微软雅黑", Font.BOLD, 20));

		

		this.tabbedPane.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent e) {
				if (tabbedPane.getSelectedComponent() == showCoursePanel
						|| tabbedPane.getSelectedComponent() == deleteCoursePanel) {
					showCoursePanel.fillTable();
					deleteCoursePanel.fillTable();
				}
			}
		});

	
	}
	
	@Override
	public void paintComponent(Graphics g){
		g.drawImage(BOTTOM, 0, 0, null);
	}
}
